package middleware

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"strings"
)

func Validation() gin.HandlerFunc {
	return func(ctx *gin.Context) {
		ctx.Next()
		if len(ctx.Errors) > 0 {
			for _, err := range ctx.Errors {
				if strings.Contains(err.Err.Error(), "Field validation") {
					ctx.JSON(http.StatusBadRequest, err.Error())
					return
				}
			}

		}
	}
}
